package com.example.boot3.controller;

import com.example.boot3.mapper.VehicleMapper;
import com.example.boot3.model.Return;
import com.example.boot3.model.Vehicle;
import com.example.boot3.service.VehicleService;
import com.example.boot3.util.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author 邹成明
 * @description 车辆信息相关接口
 */
@CrossOrigin(origins =  "*")

@RequestMapping("/vehicle")
@RestController
public class VehicleController {

    @Autowired
    private  VehicleService vehicleService;


    @PostMapping("add")
    public JsonData addVehicle(@RequestBody Vehicle vehicle) {
        Integer res = vehicleService.addVehicle(vehicle);
        if(res==1){
            return JsonData.buildSuccess("");
        }
        else{
            return JsonData.buildError("车牌号重复!");
        }

    }
    @GetMapping("vehicles_type")
    public JsonData getVehiclesByType(String[] args) {
        return JsonData.buildSuccess(vehicleService.getVehicleCountByType());
    }
    @GetMapping("/fleet/vehicle_num")
    public JsonData getVehiclesByFleet(String[] args) {
        return JsonData.buildSuccess(vehicleService.getVehicleCountByFleet());
    }
    @CrossOrigin
    @GetMapping("vehicles_info")
    public JsonData getVehiclesInfoList(String[] args) {
        return JsonData.buildSuccess(vehicleService.getVehiclesInfoList());
    }

    @GetMapping("vehicle_cost")
    public  JsonData getVehiclesCostList(){
        return JsonData.buildSuccess(vehicleService.getVehiclesCostList());
    }
    @GetMapping("vehicles_status")
    public JsonData getVehiclesStatus(String[] args) {
        return JsonData.buildSuccess(vehicleService.getVehicleCountByStatus());
    }

    @GetMapping("vehicles_use_time")
    public JsonData getVehiclesUse(String[] args) {
        return JsonData.buildSuccess(vehicleService.getVehicleUseTimesList());
    }

    @GetMapping("vehicles_mile")
    public JsonData getVehiclesMiles(String[] args) {
        return JsonData.buildSuccess(vehicleService.getVehiclesMiles());
    }

    @PostMapping("return")
    public JsonData returnVehicle(@RequestBody Return returnItem) {
        return JsonData.buildSuccess(vehicleService.returnVehicle(returnItem));
    }

    @PostMapping("delete_vehicle")
    public JsonData deleteVehicle(@RequestBody  Map<String,String> vehicle) {
        String vehicle_id = vehicle.get("vehicle_id");
//        System.out.println(vehicle);
//        System.out.println(vehicle_id);
        return JsonData.buildSuccess(vehicleService.deleteVehicle(vehicle_id));
    }

}
